package roles

import (
	p "yundian/internel/app/models/permissions"
	"yundian/internel/pkg/dingo"
)

// RolesModel 用户角色表
type RolesModel struct {
	Id        int        `gorm:"column:id" json:"id"`
	Label     string     `gorm:"column:label" json:"label"`
	Name      string     `gorm:"column:name" json:"name"`
	IsAdmin   int8       `gorm:"column:is_admin" json:"isAdmin"`
	Describe  string     `gorm:"column:describe" json:"describe"`
	Status    uint8      `gorm:"column:status" json:"status"`
	CreateAt  dingo.Time `gorm:"column:create_at" json:"createAt"`
	UpdateAt  dingo.Time `gorm:"column:update_at" json:"updateAt"`
}

type RoleWithLogin struct {
	Id        int        `gorm:"column:id" json:"id"`
	Label     string     `gorm:"column:label" json:"label"`
	Name      string     `gorm:"column:name" json:"name"`
	Describe  string     `gorm:"column:describe" json:"describe"`
	Permissions []*p.PsermissionWithActionList `gorm:"-" json:"permissions"`
}

type RoleWithPermission struct {
	RolesModel
	Permissions []*p.PsermissionWithActionList `gorm:"-" json:"permissions"`
}

// 初始化模型
func New() *RolesModel {
	return &RolesModel{}
}

// 设置参数值
func (model *RolesModel) Mutate(attrs ...RolesAttr) *RolesModel {
	RolesAttrs(attrs).Apply(model)
	return model
}

// 获取表名
func (model *RolesModel) GetTableName() string {
	return "roles"
}


